package cn.kgc.base.controller;

import cn.kgc.base.service.FileService;
import cn.kgc.commons.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>添加描述信息</p>
 *
 * @author 卢传琪
 */
@RestController
@Api(tags = "OssFile")
@RequestMapping("/oss")
@ConditionalOnClass(ResponseBodyAdvice.class)
public class OssFileController {
    @Resource
    private FileService fileService;

    @RequestMapping("/upload")
    @ApiOperation(value = "oss文件上传",httpMethod = "POST",
            produces = "application/json;charset=utf-8", response = Result.class)
    public Result upload(@RequestParam("file") MultipartFile file, HttpServletRequest request){
        String userId="0";
        String path=fileService.upload(file,userId,file.getOriginalFilename());
        return Result.success(path,request.getRequestURI().toString());
    }
}
